import { post, get } from '@/api/Http'

// TTS任务状态枚举
export enum TTSTaskStatus {
  PENDING = 'PENDING',
  PROCESSING = 'PROCESSING', 
  COMPLETED = 'COMPLETED',
  FAILED = 'FAILED'
}

// TTS任务状态描述映射
export const TTSTaskStatusDesc = {
  [TTSTaskStatus.PENDING]: '待开始',
  [TTSTaskStatus.PROCESSING]: '执行中',
  [TTSTaskStatus.COMPLETED]: '已完成',
  [TTSTaskStatus.FAILED]: '失败'
}

// 创建TTS任务请求参数
export interface CreateTTSTaskParams {
  textContent: string;
  prompt?: string;
  temperature?: number;
  topP?: number;
  topK?: number;
  speed?: number;
  refineMaxNewToken?: number;
  inferMaxNewToken?: number;
  skipRefine?: boolean;
  customVoice?: number;
}

// TTS任务信息
export interface TTSTaskInfo {
  id: number;
  textContent: string;
  status: TTSTaskStatus;
  statusDesc: string;
  fileUrl?: string;
  prompt?: string;
  temperature?: number;
  topP?: number;
  topK?: number;
  speed?: number;
  refineMaxNewToken?: number;
  inferMaxNewToken?: number;
  skipRefine?: boolean;
  customVoice?: number;
  createdTime: string;
  processStartTime?: string;
  completedTime?: string;
  taskDurationWithWait?: number;
  taskDurationWithoutWait?: number;
  duration?: number;
  errorMessage?: string;
}

// API响应格式
export interface ApiResponse<T> {
  success: boolean;
  data: T;
  message?: string;
}

/**
 * 创建TTS任务
 */
export const createTTSTask = async (params: CreateTTSTaskParams): Promise<ApiResponse<{ id: number }>> => {
  const response = await post('/tts/task/create', params)
  return response
}

/**
 * 获取任务状态
 */
export const getTTSTaskStatus = async (id: number): Promise<ApiResponse<TTSTaskInfo>> => {
  const response = await get(`/tts/task/status/${id}`, {})
  return response
}